config: clamp ra_mtu to interface MTU, and default ra_mtu to interface MTU
authorPaul Donald <[email protected]>
Thu, 30 Oct 2025 00:52:20 +0000 (01:52 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 3 Nov 2025 07:17:07 +0000 (08:17 +0100)
Set ra_mtu max to that of its interface. We also default ra_mtu if the user
did not configure it.

Signed-off-by: Paul Donald <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/296
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/config.c

index 654c329dfc86bc352a816a7e139a5f3df4b18744..a54c64c169bac011e17731fbd8cc5252344f6ceb 100644 (file)
@@ -1504,6 +1504,7 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
 
        }
 
+       iface->if_mtu = odhcpd_get_interface_config(iface->ifname, "mtu");
        if ((c = tb[IFACE_ATTR_RA_MTU])) {
                uint32_t original_ra_mtu, ra_mtu;
                original_ra_mtu = ra_mtu = blobmsg_get_u32(c);
@@ -1511,6 +1512,9 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                        ra_mtu = RA_MTU_MIN;
                else if (ra_mtu > RA_MTU_MAX)
                        ra_mtu = RA_MTU_MAX;
+               if (iface->if_mtu && ra_mtu > iface->if_mtu)
+                       ra_mtu = iface->if_mtu;
+
                iface->ra_mtu = ra_mtu;
 
                if (original_ra_mtu != ra_mtu) {
@@ -1519,6 +1523,13 @@ int config_parse_interface(void *data, size_t len, const char *name, bool overwr
                }
        }
 
+       /* Default RA MTU to the interface MTU if no value is assigned */
+       if (!iface->ra_mtu && iface->if_mtu) {
+               iface->ra_mtu = iface->if_mtu;
+               info("Defaulted %s value for interface '%s' to %d",
+                    iface_attrs[IFACE_ATTR_RA_MTU].name, iface->name, iface->ra_mtu);
+       }
+
        if ((c = tb[IFACE_ATTR_RA_SLAAC]))
                iface->ra_slaac = blobmsg_get_bool(c);